﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FaceCat
{
    /// <summary>
    /// 布局按钮
    /// </summary>
    public class LayoutButton : FCButton
    {
        /// <summary>
        /// 创建按钮
        /// </summary>
        public LayoutButton()
        {
            FCFont tFont = new FCFont("Default", 14);
            setFont(tFont);
        }

        /// <summary>
        /// 重绘方法
        /// </summary>
        public override void onPaint(FCPaint paint, FCRect clipRect)
        {
            long drawColor = FCColor.rgb(50, 50, 50);
            if (MyColor.m_style == 0)
            {
                drawColor = FCColor.rgb(150, 150, 150);
            }
            if (this == m_native.getHoveredView())
            {
                drawColor = FCColor.rgb(42, 138, 195);
            }
            int width = getWidth(), height = getHeight();
 	FCDiv parentDiv = getParent() as FCDiv;
            if (parentDiv.getVScrollBar() != null && parentDiv.getVScrollBar().isVisible())
            {
                width -= 8;
            }
            FCRect drawRect = new FCRect(2, 2, width - 2, height - 2);
            paint.drawRoundRect(drawColor, 1, 0, drawRect, 8);
            String text = getText();
            FCRect iRect = new FCRect(5, 5, 5 + height - 10, height - 5);
            drawDesignerIcon(paint, text, iRect, 0, drawColor, drawColor);
            FCFont tFont = getFont();
            FCSize tSize = paint.textSize(text, tFont);
            drawText(paint, text, drawColor, tFont, iRect.right + 2, (height - tSize.cy) / 2);
        }

        /// <summary>
        /// 重绘边线方法
        /// </summary>
        public override void onPaintBorder(FCPaint paint, FCRect clipRect)
        {
        }

        /// <summary>
        /// 绘制文字
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="text">文字</param>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="font">字体</param>
        /// <param name="x">横坐标</param>
        /// <param name="y">纵坐标</param>
        public static FCSize drawText(FCPaint paint, String text, long dwPenColor, FCFont font, int x, int y)
        {
            FCSize tSize = paint.textSize(text, font, -1);
            FCRect tRect = new FCRect(x, y, x + tSize.cx, y + tSize.cy);
            paint.drawText(text, dwPenColor, font, tRect, -1);
            return tSize;
        }

        public static void drawDesignerIcon(FCPaint paint, String cName, FCRect drawRect, int tick, long fillColor, long drawColor)
        {
            FCRect imageRect = drawRect;
            int sub = (drawRect.right - drawRect.left) / 5;
            imageRect.left += sub;
            imageRect.top += sub;
            imageRect.right -= sub;
            imageRect.bottom -= sub;
            if (cName == "Button")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                drawText(paint, "ab", drawColor, new FCFont("Default", 14, true, false, false), imageRect.left + 2, imageRect.top + 2);
            }
            else if (cName == "Calendar")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.fillRect(FCColor.rgb(255, 80, 80), new FCRect(imageRect.left + 12, imageRect.top + 12, imageRect.left + 17, imageRect.top + 18));
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 2, imageRect.top + 12);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 18, imageRect.right - 2, imageRect.top + 18);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 6, imageRect.top, imageRect.left + 6, imageRect.bottom - 2);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 2);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 18, imageRect.top, imageRect.left + 18, imageRect.bottom - 2);
                paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 8));
            }
            else if (cName == "CheckBox")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                FCRect innerRect = imageRect;
                innerRect.left += 3;
                innerRect.top += 3;
                innerRect.right -= 3;
                innerRect.bottom -= 3;
                paint.fillRect(fillColor, innerRect);
            }
            else if (cName == "Div")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
            }
            else if (cName == "Blank")
            {
                paint.drawRect(fillColor, 1, 1, imageRect);
            }
            else if (cName == "Label")
            {
                drawText(paint, "A", fillColor, new FCFont("Default", 24, true, false, false), imageRect.left + 4, imageRect.top);
            }
            else if (cName == "LinkLabel")
            {
                drawText(paint, "A", fillColor, new FCFont("Default", 24, true, false, false), imageRect.left + 4, imageRect.top);
                paint.drawLine(fillColor, 2, 0, imageRect.left + 4, imageRect.bottom + 5, imageRect.right - 4, imageRect.bottom + 5);
            }
            else if (cName == "RadioButton")
            {
                paint.drawEllipse(fillColor, 1, 0, imageRect);
                FCRect innerRect = imageRect;
                innerRect.left += 3;
                innerRect.top += 3;
                innerRect.right -= 4;
                innerRect.bottom -= 4;
                paint.fillEllipse(fillColor, innerRect);
            }
            else if (cName == "SplitLayoutDiv")
            {
                paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 1);
                paint.drawRect(fillColor, 1, 0, imageRect);
            }
            else if (cName == "TextBox")
            {
                paint.drawRoundRect(fillColor, 1, 0, imageRect, 0);
                drawText(paint, "ab|", fillColor, new FCFont("Default", 14, true, false, false), imageRect.left, imageRect.top + 2);
            }
            else if (cName == "ComboBox")
            {
                paint.fillRect(fillColor, new FCRect(imageRect.right - 5, imageRect.top, imageRect.right, imageRect.top + 5));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left, imageRect.top, imageRect.right, imageRect.top + 6));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 6, imageRect.top + 5, imageRect.right, imageRect.bottom));
                paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 10, imageRect.right - 4, imageRect.top + 10);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 14, imageRect.right - 4, imageRect.top + 14);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 18, imageRect.right - 4, imageRect.top + 18);
            }
            else if (cName == "DatePicker")
            {
                paint.fillRect(fillColor, new FCRect(imageRect.right - 5, imageRect.top, imageRect.right, imageRect.top + 5));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left, imageRect.top, imageRect.right, imageRect.top + 6));
                paint.fillRect(fillColor, new FCRect(imageRect.left + 5, imageRect.top + 5, imageRect.right - 1, imageRect.top + 10));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 5, imageRect.top + 5, imageRect.right, imageRect.bottom));
                paint.fillRect(FCColor.rgb(255, 80, 80), new FCRect(imageRect.left + 14, imageRect.top + 13, imageRect.left + 18, imageRect.top + 17));
                paint.drawLine(fillColor, 1, 0, imageRect.left + 5, imageRect.top + 13, imageRect.right - 1, imageRect.top + 13);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 5, imageRect.top + 17, imageRect.right - 1, imageRect.top + 17);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 5, imageRect.top + 21, imageRect.right - 1, imageRect.top + 21);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 10, imageRect.left + 9, imageRect.bottom - 1);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 14, imageRect.top + 10, imageRect.left + 14, imageRect.bottom - 1);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 19, imageRect.top + 10, imageRect.left + 19, imageRect.bottom - 1);
            }
            else if (cName == "Grid")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 11, imageRect.right - 2, imageRect.top + 11);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 16, imageRect.right - 2, imageRect.top + 16);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 6, imageRect.top, imageRect.left + 6, imageRect.bottom - 2);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 2);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 18, imageRect.top, imageRect.left + 18, imageRect.bottom - 2);
                paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
            }
            else if (cName == "GroupBox")
            {
                //绘制边线
                FCPoint[] points = new FCPoint[6];
                points[0] = new FCPoint(imageRect.left + 4, imageRect.top);
                points[1] = new FCPoint(imageRect.left, imageRect.top);
                points[2] = new FCPoint(imageRect.left, imageRect.bottom);
                points[3] = new FCPoint(imageRect.right, imageRect.bottom);
                points[4] = new FCPoint(imageRect.right, imageRect.top);
                points[5] = new FCPoint(imageRect.left + 18, imageRect.top);
                paint.drawPolyline(fillColor, 1, 0, points);
                drawText(paint, "xy", fillColor, new FCFont("Default", 10, true, false, false), imageRect.left + 4, imageRect.top - 8);
            }
            else if (cName == "LayoutDiv")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 6, imageRect.right - 1, imageRect.top + 6);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 1, imageRect.top + 12);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 18, imageRect.right - 1, imageRect.top + 18);
            }
            else if (cName == "TableLayoutDiv")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 1, imageRect.top + 12);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 11, imageRect.top, imageRect.left + 11, imageRect.bottom - 1);
            }
            else if (cName == "Spin")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                drawText(paint, "1", fillColor, new FCFont("Default", 10, true, false, false), imageRect.left + 2, imageRect.top);
                drawText(paint, "2", fillColor, new FCFont("Default", 10, true, false, false), imageRect.left + 2, imageRect.top + 10);
                if (true)
                {
                    FCPoint[] points = new FCPoint[3];
                    int mw = 10, mh = 10, dSize = 4;
                    points[0] = new FCPoint(imageRect.left + 7 + mw, imageRect.top + mh - dSize - 2);
                    points[1] = new FCPoint(imageRect.left + 7 + mw - dSize, imageRect.top + mh + dSize - 2);
                    points[2] = new FCPoint(imageRect.left + 7 + mw + dSize, imageRect.top + mh + dSize - 2);
                    paint.fillPolygon(fillColor, points);
                }
                if (true)
                {
                    FCPoint[] points = new FCPoint[3];
                    int mw = 10, mh = 10, dSize = 4;
                    points[0] = new FCPoint(imageRect.left + 7 + mw, mh + imageRect.top + dSize + 10);
                    points[1] = new FCPoint(imageRect.left + 7 + mw - dSize, imageRect.top + mh - dSize + 10);
                    points[2] = new FCPoint(imageRect.left + 7 + mw + dSize, imageRect.top + mh - dSize + 10);
                    paint.fillPolygon(fillColor, points);
                }
            }
            else if (cName == "TabView")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.left + 11, imageRect.top + 6));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 11, imageRect.top, imageRect.right, imageRect.top + 7));
            }
            else if (cName == "Window")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
                paint.drawLine(fillColor, 1, 0, imageRect.left + 3, imageRect.top + 11, imageRect.left + 9, imageRect.top + 11);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 3, imageRect.top + 17, imageRect.left + 9, imageRect.top + 17);
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 12, imageRect.top + 9, imageRect.left + 21, imageRect.top + 13));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 12, imageRect.top + 16, imageRect.left + 21, imageRect.top + 20));
            }
            else if (cName == "Tree")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 2, imageRect.top + 2, imageRect.left + 8, imageRect.top + 6));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 4, imageRect.top + 8, imageRect.left + 10, imageRect.top + 12));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 4, imageRect.top + 14, imageRect.left + 10, imageRect.top + 18));
                paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 4, imageRect.top + 20, imageRect.left + 10, imageRect.top + 24));
                paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top + 10, imageRect.left + 22, imageRect.top + 10);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top + 16, imageRect.left + 22, imageRect.top + 16);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top + 22, imageRect.left + 22, imageRect.top + 22);
            }
            else if (cName == "Chart")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                int pWidth = (imageRect.right - imageRect.left) / 3;
                paint.fillRect(fillColor, new FCRect(imageRect.left + 2, imageRect.top + 10, imageRect.left + pWidth, imageRect.bottom - 1));
                paint.fillRect(fillColor, new FCRect(imageRect.left + pWidth + 1, imageRect.top + 5, imageRect.left + pWidth * 2 - 1, imageRect.bottom - 1));
                paint.fillRect(fillColor, new FCRect(imageRect.left + pWidth * 2, imageRect.top + 10, imageRect.left + pWidth * 3 - 2, imageRect.bottom - 1));

            }
            else if (cName == "Custom")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                drawText(paint, "U", fillColor, new FCFont("Default", 20, true, false, false), imageRect.left + 1, imageRect.top);

            }
            else if (cName == "BandedGrid")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 11, imageRect.right - 2, imageRect.top + 11);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 16, imageRect.right - 2, imageRect.top + 16);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 6, imageRect.top, imageRect.left + 6, imageRect.bottom - 2);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 2);
                paint.drawLine(fillColor, 1, 0, imageRect.left + 18, imageRect.top, imageRect.left + 18, imageRect.bottom - 2);
                paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
                paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top + 6, imageRect.right - 1, imageRect.top + 11));
            }
            else if (cName == "Menu")
            {
                paint.drawRect(fillColor, 1, 0, imageRect);
                paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 6, imageRect.right - 1, imageRect.top + 6);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 1, imageRect.top + 12);
                paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 18, imageRect.right - 1, imageRect.top + 18);
            }
            else if (cName == "Paint")
            {
                paint.drawEllipse(fillColor, 1, 0, imageRect);
            }
        }
    }
}
